package ptij.vocoder.baseModel.common;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.ObjectToken;
import ptolemy.data.BooleanToken;
import ptolemy.data.expr.Parameter;
import ptolemy.data.type.*;

import ptij.vocoder.baseModel.*;

//////////////////////////////////////////////////////////////////////////
//// SynFiltCond
/**

@author Ivan Jeukens
@version v 0.1 07/08/2003
*/
public class SynFiltCond extends TypedAtomicActor {

    public SynFiltCond(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        a = new TypedIOPort(this, "a", true, false);
        a.setTypeEquals(BaseType.OBJECT);

        x = new TypedIOPort(this, "x", true, false);
        x.setTypeEquals(BaseType.OBJECT);

        y = new TypedIOPort(this, "y", false, true);
        y.setTypeEquals(BaseType.OBJECT);

        mem_in = new TypedIOPort(this, "mem_in", true, false);
        mem_in.setTypeEquals(BaseType.OBJECT);

        trigger = new TypedIOPort(this, "trigger", true, false);

        mem_out = new TypedIOPort(this, "mem_out", false, true);
        mem_out.setTypeEquals(BaseType.OBJECT);

        update = new Parameter(this, "update", new BooleanToken(true));
    }

    ///////////////////////////////////////////////////////////////////
    ////                     ports and parameters                  ////

    // Input ports
    public TypedIOPort a;
    public TypedIOPort x;
    public TypedIOPort mem_in;
    public TypedIOPort trigger;

    // Output Ports
    public TypedIOPort y;
    public TypedIOPort mem_out;

    public Parameter update;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void initialize() throws IllegalActionException {
        super.initialize();
        _init();
    }

    public void fire() throws IllegalActionException {
        if(trigger.hasToken(0)) {
            trigger.get(0);

            ObjectToken obj = (ObjectToken) a.get(0);
            Short [] arg1 = (Short []) obj.getValue();

            obj = (ObjectToken) x.get(0);
            Short [] arg2 = (Short []) obj.getValue();

            obj = (ObjectToken) mem_in.get(0);
            _mem = (Short []) obj.getValue();

            Short [] resp = _syn_filt(arg1, arg2);
            obj = new ObjectToken(resp);
            y.broadcast(obj);

            mem_out.broadcast(new ObjectToken(_mem));
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private methods                   ////

    private Short [] _syn_filt(Short [] ap, Short [] x) {
        Short [] y = new Short[Cnst.L_SUBFR];
        
        
        
        
        return y;
    }

    private void _init() {
        try {
            BooleanToken bt = (BooleanToken) update.getToken();
            _update = bt.booleanValue();
        }
        catch(IllegalActionException ex) {
            System.out.println(ex);
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                         private variables                 ////
 
    private Short [] _mem;
    private boolean _update;
}
